package com.hxkj.service.impl;


import com.hxkj.service.ImgSiteService;
import com.hxkj.utils.ImgUploadUtils;
import com.platform.common.domain.result.ResultDataStruct;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 站点实现类
 * <p>
 * Created by zhuzhengxin on 2018/5/19.
 */
@Service
@Slf4j
public class ImgServiceImpl implements ImgSiteService {

    private static final Logger LOGGER = LoggerFactory.getLogger(ImgServiceImpl.class);



    @Autowired
    private ImgUploadUtils imgUploadUtils;


    @Override
    public ResultDataStruct<List<String>> imgUpload(MultipartFile[] files) {
        ResultDataStruct<List<String>> result = new ResultDataStruct<>();
        List<String>  fileName = new ArrayList<>();
        //上传图片
        try {
            fileName = imgUploadUtils.UploadImgs(files);
            result.setCode(200);
            result.setData(fileName);
            result.setMessage("上传图片成功");
        } catch (IOException e) {
            e.printStackTrace();
            result.setCode(400);
            result.setMessage("上传图片失败");
        }
        return result;
    }
}
